package member;



import mvc.Data;
import mvc.MemberDao;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MemberControll {
	MemberDao memberDao;  // 원래는 MemberDao 를 직접적으로 가지고 있으면 안된당... new 식으로 새로 만들어줘서 해야하는 거라고 하는데 ..... 외부 설계로 인해 컨트롤러가 변경이 되지 않도록 하는 게 목적이라구한댄다...
			
	@RequestMapping(value = "/member/login.ddo", method=RequestMethod.GET)
	public ModelAndView form(){ // 메서드가 폼으로 변함
		ModelAndView m = new ModelAndView();
		m.setViewName("login");	
		return m;
	}
	
	@RequestMapping(value="/member/login.ddo", method=RequestMethod.POST)
	public ModelAndView submit(Data mem){
		ModelAndView m = new ModelAndView();
		
		boolean b = memberDao.login(mem);
		
		if(b) m.setViewName("log_result");
		else m.setViewName("login");
				
		
		System.out.println("mid=" + mem.getMid());
		System.out.println("pwd=" + mem.getPwd());
		
		m.addObject("member", mem);
		
		
		return m;
	}
	// 회원정보 목록 출력
	@RequestMapping("/member/select.ddo")
	public ModelAndView select(){
		ModelAndView m = new ModelAndView();
		
		m.addObject("list",memberDao.select());
		m.setViewName("select");
		return m;
	}

	public MemberDao getMemberDao() {
		return memberDao;
	}

	public void setMemberDao(MemberDao memberDao) {
		this.memberDao = memberDao;
	}
	
}


